Apache Log4j

Apache Log4j is a versatile, industrial-grade Java logging framework composed of an API, its implementation, and components to assist the deployment for various use cases. The project is actively maintained by a team of volunteers and supported by a big community.

Features

Below, we share some highlights from Log4j features.

Batteries included

Log4j bundles a rich set of components to assist various use cases.

  • Appenders targeting files, network sockets, databases, SMTP servers, etc.

  • Layouts that can render CSV, HTML, JSON, Syslog, etc. formatted outputs

  • Filters based on log event rates, regular expressions, scripts, time, etc.

  • Lookups for accessing system properties, environment variables, log event fields, etc.

Reliability

Log4j is built with solid reliability in mind. It can automatically reload its configuration upon modification and will do so without losing log events while reconfiguration occurs.

Performance

When configured correctly, Log4j can deliver excelling performance without almost any burden on the Java garbage collector, and it will do so without sacrificing reliability. Check out the Performance page for details.

Extensibility

Log4j contains a fully-fledged plugin support that users can leverage to extend functionality. You can easily add your components (layouts, appenders, filters, etc.) or customize existing ones (e.g., adding new directives to Pattern Layout or JSON Template Layout). Check out the Extending Log4j page.

Powerful API

Log4j is a logging system where the API (called Log4j API) and its implementation (called Log4j Core) is distinctly separate from each other. Log4j API provides the most feature-rich logging facade in the market; support for various Message types (such as Object or Map) besides plain String, lambda expressions, parameterized logging, markers, levels, diagnostic contexts (aka. MDC/NDC), etc. Log4j team takes backward compatibility very seriously and makes sure people relying on Log4j API gets a logging facade that is straightforward to use in a correct and future-proof way. Check out the Java API, Kotlin API and Scala API pages for further information.

No vendor lock-in

Log4j API is a generic logging facade for various logging frameworks. While Log4j Core implements it at its fullest, you can easily switch to other implementations such as Logback or JUL (java.util.logging).